/* GUI CONVERTED from poporcb2.p (converter v1.77) Wed Aug 13 20:59:51 2003 */
/* poporcb2.p - PURCHASE ORDER RECEIPT W/ SERIAL NUMBER CONTROL         */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.19.1.8.5.1 $                                                */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 7.0     LAST MODIFIED: 02/24/92    BY: pma *F085*          */
/* REVISION: 7.0     LAST MODIFIED: 07/29/92    BY: ram *F819*          */
/* REVISION: 7.3     LAST MODIFIED: 08/12/92    BY: tjs *G028*          */
/* REVISION: 7.3     LAST MODIFIED: 09/30/92    BY: afs *G116*          */
/* REVISION: 7.3     LAST MODIFIED: 12/14/92    BY: tjs *G443*          */
/* REVISION: 7.3     LAST MODIFIED: 12/17/92    BY: WUG *G455*          */
/* REVISION: 7.3     LAST MODIFIED: 01/07/93    BY: WUG *G523*          */
/* REVISION: 7.3     LAST MODIFIED: 01/11/93    BY: bcm *G425*          */
/* REVISION: 7.3     LAST MODIFIED: 05/26/93    BY: kgs *GB35*          */
/* REVISION: 7.3     LAST MODIFIED: 09/07/93    BY: WUG *GE83*          */
/* REVISION: 7.4     LAST MODIFIED: 11/23/93    BY: tjs *H082*          */
/* REVISION: 7.4     LAST MODIFIED: 10/23/93    BY: cdt *H184*          */
/* REVISION: 7.4     LAST MODIFIED: 12/20/93    BY: dpm *H074*          */
/* REVISION: 7.4     LAST MODIFIED: 10/11/94    BY: cdt *FS26*          */
/* REVISION: 7.4     LAST MODIFIED: 10/29/94    BY: bcm *FT05*          */
/* REVISION: 7.3     LAST MODIFIED: 11/15/94    BY: bcm *GO37*          */
/* REVISION: 7.4     LAST MODIFIED: 11/18/94    BY: jxz *GO56*          */
/* REVISION: 8.5     LAST MODIFIED: 12/02/94    BY: taf *J038*          */
/* REVISION: 7.4     LAST MODIFIED: 12/21/94    BY: afs *F0BJ*          */
/* REVISION: 7.4     LAST MODIFIED: 03/16/95    BY: smp *F0N5*          */
/* REVISION: 7.4     LAST MODIFIED: 04/18/95    BY: dxk *G0KY*          */
/* REVISION: 7.4     LAST MODIFIED: 08/07/95    BY: jym *G0TP*          */
/* REVISION: 8.5     LAST MODIFIED: 08/22/95    BY: tjs *J06Z*          */
/* REVISION: 8.5     LAST MODIFIED: 10/24/95    BY: taf *J053*          */
/* REVISION: 8.5     LAST MODIFIED: 02/05/96    BY: *J0CV* Robert Wachowicz*/
/* REVISION: 8.5     LAST MODIFIED: 09/26/96    BY: *G2G3* Ajit Deodhar */
/* REVISION: 8.5     LAST MODIFIED: 04/28/97    BY: *G2M7* Suresh Nayak */
/* REVISION: 8.5     LAST MODIFIED: 05/13/97    BY: *G2M4* Ajit Deodhar */
/* REVISION: 8.5     LAST MODIFIED: 10/21/97    BY: *H1G5* Seema Varma  */
/* REVISION: 8.6E    LAST MODIFIED: 05/09/98    BY: *L00Y* Jeff Wootton */
/* REVISION: 8.6E    LAST MODIFIED: 06/17/98    BY: *L020* Charles Yen  */
/* REVISION: 8.6E    LAST MODIFIED: 08/19/98    BY: *L062* Steve Nugent */
/* REVISION: 8.6E    LAST MODIFIED: 08/25/98    BY: *J2WJ* Ajit Deodhar */
/* REVISION: 8.6E    LAST MODIFIED: 09/15/98    BY: *J2ZY* Manish K.    */
/* REVISION: 9.0     LAST MODIFIED: 03/15/99    BY: *M0BG* Jeff Wootton */
/* REVISION: 9.0     LAST MODIFIED: 04/16/99    BY: *J2DG* Reetu Kapoor */
/* REVISION: 9.1     LAST MODIFIED: 10/01/99    BY: *N014* PATTI GAULTNEY     */
/* REVISION: 9.1     LAST MODIFIED: 10/25/99    BY: *N002* Bill Gates   */
/* REVISION: 9.1     LAST MODIFIED: 08/13/00    BY: *N0KQ* myb                */
/* REVISION: 9.1     LAST MODIFIED: 01/12/01    BY: *N0VL* Manish K.          */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.19.1.7     BY: Dan Herman       DATE: 04/17/02  ECO: *P043*    */
/* Revision: 1.19.1.8     BY: Patrick Rowan    DATE: 05/01/02  ECO: *P018*    */
/* $Revision: 1.19.1.8.5.1 $    BY: Rajiv Ramaiah    DATE: 08/11/03  ECO: *P0ZK*    */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/* Old ECO marker removed, but no ECO header exists *F003*              */

/* ADDED NO-UNDO  AND ASSIGN  WHEREVER MISSING                             */
/* REPLACED FIND STATEMENTS WITH FOR FIRST FOR ORACLE PERFORMANCE          */

/*! GO56 porvisb.p -- obsolete after GO37.
/*! poporcb2.p - ANY CHANGES TO THIS PROGRAM MAY ALSO HAVE TO BE MADE
                 TO PORVISB.P (bcm)
*/ *GO56*/


{mfdeclre.i}
/* NEW SHARED VARIABLES, BUFFERS AND FRAMES */

/* SHARED VARIABLES, BUFFERS AND FRAMES */
define     shared variable rndmthd         like rnd_rnd_mthd.
define     shared variable vendlot         like tr_vend_lot no-undo.
define     shared variable  crtint_amt     like trgl_gl_amt.
define     shared variable dr_acct         like trgl_dr_acct extent 6.
define     shared variable dr_sub          like trgl_dr_sub extent 6.
define     shared variable dr_cc           like trgl_dr_cc extent 6.
define     shared variable eff_date        like glt_effdate.

define     shared variable exch_rate       like exr_rate.

define     shared variable exch_rate2      like exr_rate.
define     shared variable exch_ratetype   like exr_ratetype.
define     shared variable exch_exru_seq   like exru_seq.

define     shared variable is-return       like mfc_logical no-undo.
define     shared variable new_db          like si_db.
define     shared variable old_db          like si_db.
define     shared variable old_status      like pod_status.
define     shared variable po_recno        as recid.
define     shared variable pod_recno       as recid.
define     shared variable price           like tr_price.
define     shared variable project         like pvo_project.
define     shared variable ps_nbr          like prh_ps_nbr.
define     shared variable openqty         like mrp_qty.
define     shared variable qty_ord         like pod_qty_ord.
define     shared variable rcv_type        like poc_rcv_type.
define     shared variable replace         like mfc_logical.
define     shared variable receivernbr     like prh_receiver.
define     shared variable sct_recno       as recid.
define     shared variable site            like pod_site no-undo.
define     shared variable stdcst          like tr_price.
define     shared variable updt_blnkt      like mfc_logical.
define     shared variable updt_blnkt_list as character no-undo.
define     shared variable yes_char        as character format "x(1)".
define     variable use_pod_um_conv        as logical no-undo.
define     shared variable qopen           like pod_qty_rcvd.
define     shared variable receipt_date    like prh_rcp_date no-undo.

define     input parameter ship_date     like prh_ship_date no-undo.
define     input parameter i_shipto      like abs_shipto    no-undo.
define     input parameter consign_flag  like mfc_logical   no-undo.
define     input parameter p_ip_is_usage like mfc_logical   no-undo.

define     shared workfile tax_wkfl
   field tax_nbr           like pod_nbr
   field tax_line          like pod_line
   field tax_env           like pod_tax_env
   field tax_usage         like pod_tax_usage
   field tax_taxc          like pod_taxc
   field tax_in            like pod_tax_in
   field tax_taxable       like pod_taxable
   field tax_price         like prh_pur_cost.

/* LOCAL VARIABLES, BUFFERS AND FRAMES */
define buffer      poddet      for pod_det.
define buffer      pomstr      for po_mstr.
define variable    over_qty    like pod_qty_rcvd no-undo.

for po_mstr
      fields (po_cls_date po_nbr po_recurr po_stat)
      where recid(po_mstr) = po_recno no-lock:
end. /* FOR FIRST PO_MSTR */

find pod_det where recid(pod_det) = pod_recno exclusive-lock no-error.

use_pod_um_conv = no.

for first pt_mstr
   fields( pt_part pt_um )
   where pt_part = pod_part no-lock:
end. /* FOR FIRST PT_MSTR */
if available pt_mstr and pod_rum = pt_um
   then
   use_pod_um_conv = yes.
else
   use_pod_um_conv = no.

/* CREATE PURCHASE RECEIPT HISTORY RECORD */
if pod_qty_chg <> 0 then do:

   /* ADDED SECOND EXCHANGE RATE, TYPE, SEQUENCE */
   /* INSERTED dr_sub[1] AS 13TH PARAMETER IN LIST BELOW */
   /* ADDED 21nd INPUT PARAMETER I_SHIPTO                */
   {gprun.i ""poporcb7.p""
      "(input pod_recno,
        input ship_date,
        input po_recno,
        input sct_recno,
        input rcv_type,
        input site,
        input is-return,
        input eff_date,

        input pod__qad04[1],
        input receivernbr,
        input ps_nbr,
        input dr_acct[1],
        input dr_sub[1],
        input dr_cc[1],
        input project,
        input price,
        input exch_rate,
        input exch_rate2,
        input exch_ratetype,
        input exch_exru_seq,
        input yes_char,
        input i_shipto,
        input-output crtint_amt,
        input use_pod_um_conv,
        input consign_flag,
        input-output stdcst)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   assign pod__qad04[1] = "".
end.  /* if pod_qty_chg <> 0 */

/* WHEN PO IS RAISED IN STOCKING UM AND RECEIVED OR RETURNED       */
/* IN ALTERNATE UM; CONVERT THE QUANTITY RECEIVED OR RETURNED BY   */
/* DIVIDING WITH CONVERSION FACTOR TO AVOID ROUNDING ERRORS. */

/*UPDATE PURCHASE ORDER QUANTITY RECEIVED OR RETURNED */
if is-return then do:
   if use_pod_um_conv then do:
      assign
         pod_qty_rtnd = pod_qty_rtnd + pod_qty_chg / pod_um_conv
         pod_cum_qty[1] = pod_cum_qty[1] - pod_qty_chg / pod_um_conv.
   end. /* IF USE_POD_UM_CONV */
   else do:
      assign
         pod_qty_rtnd = pod_qty_rtnd + pod_qty_chg * pod_rum_conv
         pod_cum_qty[1] = pod_cum_qty[1] - pod_qty_chg * pod_rum_conv.
   end. /* ELSE DO */
end.
else do:
   if use_pod_um_conv then do:
      assign
         pod_qty_rcvd = pod_qty_rcvd + pod_qty_chg / pod_um_conv
         pod_cum_qty[1] = pod_cum_qty[1] + pod_qty_chg / pod_um_conv.
   end. /* IF USE_POD_UM_CONV */
   else do:
      assign
         pod_qty_rcvd = pod_qty_rcvd + pod_qty_chg * pod_rum_conv
         pod_cum_qty[1] = pod_cum_qty[1] + pod_qty_chg * pod_rum_conv.
   end. /* ELSE DO */
end.

if is-return and pod_qty_chg <> 0 then pod_status = "".

if is-return and replace and not pod_sched then do:
   assign
      po_recno = recid(po_mstr)
      pod_recno = recid(pod_det).
   /* ADDED INPUT PARAMETER use_pod_um_conv TO HANDLE ROUNDING ERROR */
   {gprun.i ""porvisc.p"" "(input use_pod_um_conv)"}
/*GUI*/ if global-beam-me-up then undo, leave.

end.

if pod_sched then do:
   {gprun.i ""rsmrw.p""
      "(input pod_nbr, input pod_line, input no)"
      }
/*GUI*/ if global-beam-me-up then undo, leave.

end.

if pod_blanket <> "" and not is-return then do for poddet:

      find poddet where poddet.pod_nbr  = pod_det.pod_blanket

         and poddet.pod_line = pod_det.pod_blnkt_ln
      exclusive-lock no-error.

      if available poddet then do:

         /* UPDT_BLNKT_LIST IS A COMMA SEPARATED LIST OF ALL POD_LINE     */
         /* NUMBERS WHICH MUST HAVE THE BLANK PO RELEASE QUANTITY UPDATED */
         if can-do(updt_blnkt_list,string(poddet.pod_line)) then
            updt_blnkt = yes.
         else updt_blnkt = no.

         if updt_blnkt then do for pomstr:

               /* FLIP THE SIGN FOR RETURNS */
               if is-return then
                  pod_det.pod_qty_chg = - pod_det.pod_qty_chg.

               find pomstr
                  where pomstr.po_nbr = pod_det.pod_blanket
               exclusive-lock no-error.

               /* Increase blanket released qty by qty overreceived */
               /* Qty overreceived is the larger of this receipt  */
               /* and the total amount overreceived on this line. */
               over_qty = pod_det.pod_qty_chg * pod_det.pod_rum_conv.
               if poddet.pod_um_conv <> pod_det.pod_um_conv then
                  over_qty = over_qty / poddet.pod_rum_conv.
               if over_qty > 0 then
               over_qty =
               min(over_qty, pod_det.pod_qty_rcvd - pod_det.pod_qty_ord).
               else
               over_qty =
               max(over_qty, pod_det.pod_qty_rcvd - pod_det.pod_qty_ord).
               poddet.pod_rel_qty = poddet.pod_rel_qty + over_qty.

               if pomstr.po_recur
                  then
               poddet.pod_qty_chg =
               min((poddet.pod_qty_ord - poddet.pod_rel_qty),
                  poddet.pod_qty_chg).
               if pomstr.po_recur = false
                  or (poddet.pod_qty_ord - poddet.pod_rel_qty <= 0 )
                  then poddet.pod_qty_chg = 0.

               if (poddet.pod_qty_ord - poddet.pod_rel_qty <= 0)
                  then poddet.pod_status = "C".

               /* Close Blanket PO if all lines released */
               find first poddet where poddet.pod_nbr = pod_det.pod_blanket
                  and poddet.pod_status = "" no-lock no-error.
               if not available poddet then do:
                  assign
                     pomstr.po_cls_date = today
                     pomstr.po_stat = "C".
               end.

               /* RESTORE THE SIGN FOR RETURNS */
               if is-return then
                  pod_det.pod_qty_chg = - pod_det.pod_qty_chg.

            end. /* if updt_blnkt */

            find poddet where poddet.pod_nbr  = pod_det.pod_blanket

               and poddet.pod_line = pod_det.pod_blnkt_ln
            exclusive-lock no-error.

            if poddet.pod_um_conv = pod_det.pod_um_conv then
            poddet.pod_qty_rcvd = poddet.pod_qty_rcvd
            + pod_det.pod_qty_chg
            * pod_det.pod_rum_conv.
            else
            poddet.pod_qty_rcvd = poddet.pod_qty_rcvd
            + pod_det.pod_qty_chg
            * pod_det.pod_rum_conv
            * pod_det.pod_um_conv
            / poddet.pod_um_conv.
         end.

         /* Update the blanket order in the remote database */
         old_db = global_db.

         if available poddet and pod_po_db <> "" and
            pod_po_db <> global_db then do:

            new_db = pod_po_db.
            {gprun.i ""gpaliasd.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

            {gprun.i ""poporcb3.p""
               "(pod_det.pod_blanket, pod_det.pod_blnkt_ln, updt_blnkt,
                 poddet.pod_rel_qty, poddet.pod_qty_chg, poddet.pod_qty_rcvd)"
               }
/*GUI*/ if global-beam-me-up then undo, leave.

            new_db = old_db.
            {gprun.i ""gpaliasd.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

         end.

      end.

      if not pod_sched
      then do:
         if (pod_qty_ord - pod_qty_rcvd) / pod_qty_ord <= 0
            or pod_qty_ord = 0
         then
            pod_status = "c".

         if pod_bo_chg       = 0
            and (pod_qty_ord - pod_qty_rcvd) / pod_qty_ord > 0
            and old_status       <> "c"
            and old_status       <> "x"
            and pod_rma_type     <>  "O"
            and pod_rma_type     <>  "I"
            and ( not is-return )
            and ((consign_flag
                  and p_ip_is_usage  = no)
                 or (consign_flag    = no))
         then
            pod_status = "x".
      end. /* IF NOT pod_sched */

      if is-return and pod_qty_chg <> 0
         and old_status = "x"  then
         assign pod_status = "x" .
      /* UPDATE MRP AND TRANSACTION HISTORY */
      {gprun.i ""poporcb5.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


      /* RESET TEMPORARY VARIABLES */
      assign pod_qty_chg = 0
         pod_bo_chg = 0
         pod_ps_chg = 0
         pod_cost_chg = 0
